package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Praise;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.service.impl.StrategyServiceImpl;
import cn.wolfcode.trip.base.util.JSONResult;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/praises")
public class PraiseController {
    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private ITravelService travelService;

    @Autowired
    private IStrategyCommentService commentService;

    @Autowired
    private IDailyService dailyService;

    @Autowired
    private IQuestionService questionService;

    //对某个攻略做收藏以及点赞操作
    @PostMapping("{strategyId}/{userId}")
    private JSONResult insertRelation(@PathVariable Long strategyId,@PathVariable Long userId,Integer state){

        strategyService.insertRelation(userId,strategyId,state);
        return new JSONResult();
    }
    @GetMapping("{strategyId}/{state}")
    private Map<String,Object> getPraiseNums(@PathVariable Long strategyId,@PathVariable Integer state){
        return strategyService.selectPraiseNums(strategyId,state);
    }
    @GetMapping("{userId}/{strategyId}/{state}")
    private Boolean getRelation(@PathVariable Long userId,@PathVariable Long strategyId,@PathVariable Integer state){

        return strategyService.selectRelation(userId,strategyId,state);
    }
    @DeleteMapping("{strategyId}/{userId}/{state}")
    private JSONResult deleteRelation(@PathVariable Long strategyId,@PathVariable Long userId,@PathVariable Integer state){
        strategyService.deleteRelation(strategyId,userId,state);
        return new JSONResult();
    }



    //针对某个作者的某篇游记的收藏和点赞
    //查询某篇游记有没有被某个用户收藏或者点赞
    @GetMapping("travels/{travelId}")
    public Boolean queryRelation(@PathVariable Long travelId,Integer state){
        return travelService.queryIsRelation(travelId,state);
    }

    //查询记录数,判断当前页面的游记,是否包含这个id
    @GetMapping("travels/{authorId}/{userId}")
    public List getTravelId(@PathVariable Long authorId, @PathVariable Long userId, Integer state){
        return travelService.queryRows(authorId,userId,state);
    }

    //保存某篇游记的关系
    @PostMapping("travels")
    public JSONResult insertRelation(Praise obj){
        travelService.insertRelation(obj);
        return new JSONResult();
    }
    //删除某篇游记的收藏/关注
    @DeleteMapping("travels/{travelId}/{userId}/{state}")
    public JSONResult deleteTravelContentRelation(@PathVariable Long travelId ,@PathVariable Long userId,@PathVariable Integer state){
        travelService.deleteTravelRelation(travelId,userId,state);
        return new JSONResult();
    }




    //获取某个攻略下的某个用户的某个点评
   /* praise/strategies/{strategyId}/authors/{authorsId}/strategeComment/{strategyCommentId}/{userId}*/
    @PostMapping("strategies")
    public JSONResult insertCommentPraise(Praise obj){
        commentService.insertCommentPraise(obj);
        return new JSONResult();
    }

    @DeleteMapping("strategies")
    public JSONResult getCommentPraise(Praise obj){
        commentService.deleteCommentPraise(obj);
        return new JSONResult();
    }
    @GetMapping("strategies")
    public Boolean deleteCommentPraise(Praise obj){
        return  commentService.hasCommentPraise(obj);
    }





    //日报的收藏
    @GetMapping("dailies/{dailyId}")
    public Boolean getDailyIsLike(@PathVariable Long dailyId,Integer state){
        return dailyService.queryIsLike(dailyId,state);
    }

    @PostMapping("dailies")
    public JSONResult saveDailyIsLike(Praise obj){
        dailyService.saveDailyIsLike(obj);
     return new JSONResult();
    }


    @DeleteMapping("dailies")
    public JSONResult delete(Praise obj){
        dailyService.deleteDailyIsLike(obj);
        return new JSONResult();
    }


    //问题的点赞
    @GetMapping("questions")
    public Boolean getQuestionIsLike(Praise obj){
        return questionService.queryIsLike(obj);
    }

    @PostMapping("questions")
    public JSONResult saveQuestionIsLike(Praise obj){
        questionService.saveDailyIsLike(obj);
        return new JSONResult();
    }


    @DeleteMapping("questions")
    public JSONResult deleteQuestionIsLike(Praise obj){
        questionService.deleteDailyIsLike(obj);
        return new JSONResult();
    }





}
